/*
 * Copyright 2012-2014 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.jqd.framework.core.hessian.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 
 * TODO
 * 
 * @author liaozhicheng.cn@gmail.com
 * @date 2012-6-11
 * @since 1.0
 */
public class ServiceResponse implements Serializable {
	
	private static final long serialVersionUID = 4844378233368623441L;
	
	private static final String CODE_SUCCESS = "success";
	
	private static final String CODE_FAIL = "fail";
	
	public static final String SERVICE_RESPONSE_RESULT = "SERVICE_RESPONSE_RESULT";
	
	private String responseCode = CODE_SUCCESS;
	
	private String responseMsg;
	
	private Map<String, Object> model = null;
	
	
	public ServiceResponse() {
	}
	
	
	public ServiceResponse(Map<String, Object> model, String responseCode) {
		this.model = model;
		this.responseCode = responseCode;
	}
	
	
	public Map<String, Object> getModel() {
		return this.model;
	}
	
	
	public void setModel(Map<String, Object> model) {
		this.model = model;
	}
	
	
	public String getResponseCode() {
		return this.responseCode;
	}
	
	
	public void setResponseCode(String responseCode) {
		this.responseCode = responseCode;
	}
	
	
	public void setSuccess(boolean success) {
		if (success)
			this.responseCode = CODE_SUCCESS;
		else
			this.responseCode = CODE_FAIL;
	}
	
	
	public boolean getSuccess() {
		if (CODE_SUCCESS.equals(this.responseCode))
			return true;
		else
			return false;
	}
	
	
	public String getResponseMsg() {
		return this.responseMsg;
	}
	
	
	public void setResponseMsg(String responseMsg) {
		this.responseMsg = responseMsg;
	}
	
	
	public void setResponseResult(Object obj) {
		if (this.model == null) {
			this.model = new HashMap<String, Object>();
		}
		
		this.model.put(SERVICE_RESPONSE_RESULT, obj);
	}
	
	
	public Object getResponseResult() {
		if (this.model == null) {
			return null;
		}
		
		return this.model.get(SERVICE_RESPONSE_RESULT);
	}
	
}
